package ru.infosystem.server;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import ru.infosystem.client.business.TaskAnalyser;

/**
 *
 * @author akoshi
 */
public class ThreadedRequestHandler implements Runnable {

    private ObjectInputStream in = null;
    private ObjectOutputStream out = null;
    private Socket socket = null;

    public ThreadedRequestHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            out = new ObjectOutputStream(socket.getOutputStream());
            in = new ObjectInputStream(socket.getInputStream());
            TaskAnalyser t = new TaskAnalyser(in, out);

            while (true) {
                    try {
                        System.err.println("new thread");
                        t.runTask();
                    } catch (NoSuchMethodException n) {
                        System.err.println(n);
                    }
                
            }
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection to: "
                    + socket.getInetAddress() + ":" + socket.getPort());
        }
    }
}
